package com.gillion.grule.client.components;

import com.gillion.grule.client.core.Component;
import com.gillion.grule.client.core.Context;
import com.gillion.grule.client.core.ExecuteComponent;
import org.apache.commons.lang3.StringUtils;

@Component("Constant")
public class ConstantComponent extends ExecuteComponent {
    public <T> T execute(String express, Context context) {
        String[] exps = express.split("\\|");
        Object val = null;
        if (exps.length == 1) {
            val = exps[0];
        } else if (StringUtils.equals(exps[0], "String")) {
            val = exps[1];
        } else if (StringUtils.equals(exps[0], "Integer")) {
            val = Integer.valueOf(exps[1]);
        } else if (StringUtils.equals(exps[0], "Float")) {
            val = Float.valueOf(exps[1]);
        } else if (StringUtils.equals(exps[0], "Long")) {
            val = Long.valueOf(exps[1]);
        } else if (StringUtils.equals(exps[0], "Double")) {
            val = Double.valueOf(exps[1]);
        }
        return (T)val;
    }
}
